package com.teamwhole.modules.sys.web;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.teamwhole.common.model.ResultInfo;
import com.teamwhole.modules.sys.entity.Department;
import com.teamwhole.modules.sys.service.DepartmentService;

@Component
@Path("/sys/department")
@Consumes("application/json;charset=utf-8")
@Produces("application/json;charset=utf-8")
public class DepartmentResource {
	
	@Autowired
	private DepartmentService deptService;
	
	@Path("/get")
	@GET
	public Department get(@QueryParam("id") String id) {
		return deptService.get(id);
	}
	
//	@Path("/list")
//	@POST
//	public Object list(Department entity){
//		if (StringUtils.isBlank(entity.getId())) {
//			entity.setId("0");
//		}
//		return deptService.findNextLevel(entity);
//	}
	
	@Path("/list")
	@POST
	public Object listTree(Department model){
		return deptService.findList(model);
	}
	
	@Path("/create")
	@POST
	public ResultInfo create(Department model) {
		deptService.save(model);
		return ResultInfo.ok();
	}
	
	@Path("/update")
	@POST
	public ResultInfo update(Department model) {
		deptService.save(model);
		return ResultInfo.ok();
	}
	
	@Path("/delete")
	@GET
	public ResultInfo delete(@QueryParam("id") String id) {
		deptService.delete(id);
		return ResultInfo.ok();
	}
	
}
